package server;

import java.io.*;
import java.net.Socket;

public class TimeServiceHandler implements Runnable {
	private Socket s;
	public TimeServiceHandler(Socket s) {
		this.s = s;
	}
	public void run() {
		PrintWriter pw = null;
		BufferedReader in = null;
		try {
			in = new BufferedReader(new InputStreamReader(s.getInputStream()));
			pw = new PrintWriter(new OutputStreamWriter(s.getOutputStream())); // 通过这个socket打开一个输出流
			while (true) {
				System.out.println("runing.....");
				String req = in.readLine();
				if ("ask".equals(req)) {
					pw.println(new java.util.Date()); // 写一个日期
					pw.flush(); // 将这些用到的东西一次给他clear.
					System.out.println(req + " :发送数据完毕。");
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				pw.close();
				s.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}